<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.List" %>
<%@ page import="net.zdsoft.keel.util.*" %>
<%@ page import="net.zdsoft.keel.util.StringUtils" %>
<%@ page import="net.zdsoft.wpchat.support.util.PageUtils" %>
<%@ page import="net.zdsoft.wpchat.support.action.auth.GroupAction" %>
<%@ page import="net.zdsoft.wpchat.support.entity.AuthGroup" %>
<%@ page import="net.zdsoft.wpchat.support.enums.AuthGroupTypeEnum" %>
<%
GroupAction action = (GroupAction) PageUtils.getAction();
List<AuthGroup> groupList = action.getGroupList();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN" xml:lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台</title>
<style type="text/css" media="all">@import url("../../css/style.css");</style>
<script type="text/javascript" language="javascript" src="../../script/jquery-1.7.2.js"></script>
<script type="text/javascript" language="javascript" src="../../script/js-utils.js"></script>
<script language="JavaScript">
<!--
function submit(action,operatorId){
  var attention="";
  if(action=="authReOpen.htm"){
    attention="您确定要对该用户进行解冻？";
  }
  else if(action =="authClose.htm"){
    attention="您确定要对该用户进行冻结？";
  }
  else if(action =="authRemove.htm"){
    attention="您确定要删除该用户吗？";
  }
  if(confirm(attention)){
    window.location.href=action+"?operatorId=" + operatorId;
  }
}

function modifyGroup(id, name, description){
  document.authGroupForm.groupId.value = id;
  document.authGroupForm.name.value = name;
  document.authGroupForm.description.value = description;
}

function addOrModifyGroup(){
  var form = document.authGroupForm;
  form.okBtn.disabled = true;
  var id = form.groupId.value;
  var name = form.name.value;
  var description = form.description.value;
  
  $.post("addModifyGroup.htm",{"id":id,"name":name,"description":description},function(data){
      if(isMessageReply(data)){
          location.href = location.href;
      }else{
          printReply(data);
      }
      form.okBtn.disabled = false;
  });
}

function removeGroup(groupIds){
  if (confirm("您确定要删除选择的组吗？")){
    $.post("removeGroup.htm",{"groupIds":groupIds},function(data){
        if(isMessageReply(data)){
            location.href = location.href; 
        }else{
            printReply(data);
        }
    });
  }
}
//-->
</script>
</head>
<body> 
<div id="tableMain">
  <div id="message"></div>
  <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
    <tr class="titleTr">
      <td align="center" width="5%">序号</td>
      <td align="center" width="15%">组名</td>
      <td align="center" width="45%">描述</td>
      <td align="center" width="10%">类型</td>
      <td align="center" width="15%">创建时间</td>
      <td align="center" width="10%">操作</td>
    </tr><%
for (int i = 0; i < groupList.size(); i++) {
  AuthGroup group = groupList.get(i); %>
    <tr>
      <td align="center"><%=i+1%></td>
      <td align="center"><%=StringUtils.htmlFilter(group.getName())%></td>
      <td><%=StringUtils.htmlFilter(group.getDescription())%></td>
      <td align="center"><%=AuthGroupTypeEnum.valueOf(group.getType())%></td>
      <td align="center"><%=DateUtils.date2StringByDay(group.getCreationTime())%></td>
      <td align="center"><%
  if (AuthGroupTypeEnum.CUSTOM.equals(group.getType())) { %>
        <a href="javascript:modifyGroup('<%=group.getId()%>','<%=StringUtils.linkFilter(group.getName())%>','<%=StringUtils.linkFilter(StringUtils.ignoreNull(group.getDescription()))%>')">编辑</a>&nbsp;
        <a href="javascript:removeGroup('<%=group.getId()%>')">删除</a><%
  } %>
        </td>
    </tr><%
} %>  
  </table>
 <form name="authGroupForm" action="javascript:addOrModifyGroup()" method="post"">
 <input type="hidden" name="groupId" value=""/>
 <table id="dataTable" border="0" align="center" cellpadding="5" cellspacing="1">
  <tr>
    <td width="20%" class="titleTd"> 组名:</td>
    <td><input name="name" type="text" size="60" maxlength="60" value="" /></td>
    </tr>
    <tr >
    <td height="100px" width="20%" class="titleTd" > 描述:</td>
    <td><textarea rows="2" style="word-break:break-all;" name="description" style="width:100%"></textarea></td>
    </tr>
 </table>
    <div id="buttonRight">
    <input type="button" name="okBtn" onclick="addOrModifyGroup()" value=" 保存 " class="colorButton" />
    <input type="button" onclick="history.back(-1)" value=" 返回 " class="colorButton" />
    </div>
  </form>
</div>
</body>
</html>
